package com.iwhalecloud.bss.kite.cucc.service.attr.handler;

import com.iwhalecloud.bss.kite.common.constant.KeyConsts;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.service.util.ProdCateUtil;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.attr.handler.AbstractAttrHandler;
import com.ztesoft.bss.common.exception.BssException;

import java.util.Objects;


/**
 * @author zhoubang
 * 云聚节点-云联网专线接入产品-新版-客户CE联系人电话联动
 */
public class GlowedNodePhoneServiceAttrHandler extends AbstractAttrHandler<KiteInst, AttrData> {


    @Override
    public void before(KiteAttr attr, KiteInst inst, String value, AttrData data) {
        if (Objects.isNull(attr)) {
            return;
        }
        //当输入值以“+”开头时，不校验
        if(KiteStringUtils.isNotEmpty(value)){
            if(value.startsWith("+")){
                attr.setAttrFormat("");
            }else{
                boolean matches = value.matches("^(1[0-9]{10})$");
                if (!matches) {
                    BssException.throwOut("", "", "联系人手机号格式有误，请输入正确的手机号格式！");
                }
            }
        }
    }

}
